package com.ptswitch.material.dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.ptswitch.material.model.material.Bom;

public interface BomMapper {
    @Select("select * from bom where id=#{id}")
    Bom findById(@Param("id") long id);

    @Select("select * from bom where code=#{code} and version=#{version}")
    Bom findByCodeAndVersion(@Param("code") String code, @Param("version") String version);

    @Delete("delete from bom where id=#{bom.id}")
    void delete(@Param("bom") Bom bom);

    @Select("select * from bom")
    List<Bom> findAll(long first, long size);

    @Select("select count(*) from bom")
    long countAll();

    @Insert("insert into bom(code,fileName,name,origFile,remark,version)"//
            + " values(#{bom.code},#{bom.fileName},#{bom.name},#{bom.origFile}"//
            + " ,#{bom.remark},#{bom.version}) returning id")
    long add(@Param("bom") Bom bom);

    @Update("update bom set code=#{bom.code},fileName=#{bom.fileName},name=#{bom.name}"//
            + ",origFile=#{bom.origFile},remark=#{bom.remark},version=#{bom.version})")
    void update(@Param("bom") Bom bom);

    @Select("select * from bom where code like #{like} or name like #{like} or remark like #{like}")
    List<Bom> findLike(@Param("like") String like, long first, long size);

    @Select("select count(*) from bom where code like #{like} or name like #{like}"//
            + " or remark like #{like}")
    long countLike(@Param("like") String like);

}
